﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinRTFramework.Common;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.DataTransfer.ShareTarget;
using WinRTFramework;
using WinRTFramework.Contracts;

namespace ShareTarget.ViewModels
{
    public class MainPageViewModel_Showcase : Bindable
    {
        public string SharedText { get; set; }

        DelegateCommand _reportCompletedCommand;
        public DelegateCommand ReportCompletedCommand
        {
            get
            {
                return _reportCompletedCommand = _reportCompletedCommand ?? new DelegateCommand(() => _shareOperation.ReportCompleted());
            }
        }

        #region ISharingTarget
        public IEnumerable<string> SupportedFormats
        {
            get { yield return StandardDataFormats.Text; }
        }

        ShareOperation _shareOperation;
        public async void OnShareReceived(ShareOperation shareOperation)
        {
            _shareOperation = shareOperation;

            SharedText = await shareOperation.Data.GetTextAsync();
            _shareOperation.ReportDataRetrieved();
        }
        #endregion
    }
}
